package one.stand.config;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import one.stand.util.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author: QIK
 * @CreateDate: 2019/5/13 12:54
 */
@Component
@Data
public class ExtJsonConfig {
    @Value("${extjson.uploadUrl}")
    private String uploadUrl;
    @Value("${extjson.baseUrl}")
    private String baseUrl;
    @Value("${extjson.wssUrl}")
    private String wssUrl;
    @Value("${extjson.downloadFile}")
    private String downloadFile;
    @Value("${extjson.location}")
    private String location;
    @Autowired
    OssUtil ossUtil;
    /**
     * 获取extjson
     * @param appid
     * @param jumpAppId
     * @param jumpName
     * @param companyKey
     * @return
     */
    public JSONObject getExtJSON(String appid,String jumpAppId,String jumpName,String companyKey,String headImg,String myAppName){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("extAppid",appid);
        JSONObject extJSON=new JSONObject();
        extJSON.put("jumpAppId",jumpAppId);
        extJSON.put("jumpName",jumpName);
        extJSON.put("companyKey",companyKey);
        extJSON.put("headImg",headImg);
        extJSON.put("uploadUrl",uploadUrl);
        extJSON.put("baseUrl",baseUrl);
        extJSON.put("wssUrl",wssUrl);
        extJSON.put("ossUrl",ossUtil.getOssUrl());
        jsonObject.put("ext",extJSON);
        jsonObject.put("extEnable",true);
        jsonObject.put("navigateToMiniProgramAppIdList",new String[]{jumpAppId});
        JSONObject windowJson=new JSONObject();
        windowJson.put("navigationBarTitleText",myAppName);
        jsonObject.put("window",windowJson);
        return jsonObject;
    }
}
